package com.android.stockme.backend.configuration;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import com.android.stockme.frontend.StockMeTabActivity;

public class PersistentConfigurationManager implements IConfigurationManager {


	/**
	 * @uml.property   name="stockConfigurations"
	 * @uml.associationEnd   multiplicity="(1 1)" inverse="persistentConfigurationManager:com.android.stockme.backend.configuration.IStockConfiguration" qualifier="symbol:java.util.Map com.android.stockme.backend.configuration.IStockConfiguration"
	 */
	private Map<String, IStockConfiguration> stockConfigurationsMap = null;
	private Map<EConfigurationChangedEvents, Collection<IConfigurationChangedListener>> event2listeners = null;
	private ConfigFile configFile = null;

	private enum EConfigurationChangedEvents
	{
		STOCK_ADDED_EVENT,
		STOCK_REMOVED_EVENT,
		HISTORY_LENGTH_CHANGED_EVENT,
		STOCK_TICK_FREQUENCY_CHANGED_EVENT,
		NEWS_TICK_FREQUENCY_CHANGED_EVENT,
		FINANCE_WEBSITE_CHANGED_EVENT
	}
	
	public PersistentConfigurationManager()
	{
		this.stockConfigurationsMap = new HashMap<String, IStockConfiguration>();
		this.initListenersMap();
		this.configFile = new ConfigFile(this.stockConfigurationsMap);

		
	}
	
	private class ConfigFile
	{
		
		private static final String CONFIG_FILE_NAME = "ConfigFile.xml";
		private final String[] DatabaseWebSites = {"Google Finance Web Site","Yahoo Finance Web Site"};
		private final String defaultFinanceWebsite = DatabaseWebSites[0];
		private static final int defaultNewsHistoryLength = 5;
		private static final int defaultNewsTickFrequencySec = 30;
		private static final int defaultStockTickFrequencySec = 30;
		private static final boolean defaultNotificationState = false;
		
		private int newsHistoryLength = defaultNewsHistoryLength;
		private int newsTickFrequencySec = defaultNewsTickFrequencySec;
		private int stockTickFrequencySec = defaultStockTickFrequencySec;
		private String financeWebsite = defaultFinanceWebsite;
		private boolean notificationState = defaultNotificationState;

		
		public ConfigFile(Map<String, IStockConfiguration> stockConfigurationsMap)
		{

			
			File file = StockMeTabActivity.activity().getApplication().getFileStreamPath(CONFIG_FILE_NAME);

			if (file.exists())
			{//The config file exists
				
				getConfigFromXMLFile(stockConfigurationsMap);
				
			}
			else
			{//The config file doesn't exists - create new config file & save default configurations 
				
				try {
					if (!StockMeTabActivity.activity().getApplication().getFilesDir().exists())
						StockMeTabActivity.activity().getApplication().getFilesDir().mkdir();
					file.createNewFile();//create the config file
				    FileWriter fw = new FileWriter(file);
				    fw.write("<newsHistoryLength>"+newsHistoryLength+"</newsHistoryLength>\n" +
				    		 "<newsTickFrequencySec>"+newsTickFrequencySec+"</newsTickFrequencySec>\n"+
				    		 "<stockTickFrequencySec>"+stockTickFrequencySec+"</stockTickFrequencySec>\n"+
				    		 "<notificationState>"+notificationState+"</notificationState>\n"+
				    		 "<financeWebsite>"+financeWebsite+"</financeWebsite>\n");
				    
				    fw.close();
					
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
					
		}//ConfigFile Ct'r
		

		private Map<String, IStockConfiguration> getConfigFromXMLFile(Map<String, IStockConfiguration> map)
		{
			try 
			{
				XmlPullParserFactory factory;
				factory = XmlPullParserFactory.newInstance();
				factory.setNamespaceAware(true);
				XmlPullParser xpp = factory.newPullParser();
				FileReader reader = new FileReader (StockMeTabActivity.activity().getApplication().getFileStreamPath(CONFIG_FILE_NAME));
				
				xpp.setInput(reader );
				int eventType = xpp.getEventType();
				while (eventType != XmlPullParser.END_DOCUMENT) 
				{//parse the XML file
					
					if(eventType == XmlPullParser.START_TAG)
					{
						System.out.println("Start tag "+xpp.getName());
						String tagName = xpp.getName();
						xpp.next();//go after the START_TAG
						if (tagName.equals("newsHistoryLength"))
						{
							newsHistoryLength = Integer.parseInt(xpp.getText().trim());//remove
						}else
						if (tagName.equals("newsTickFrequencySec"))
						{
							newsTickFrequencySec = Integer.parseInt(xpp.getText().trim());//remove
						}else
						if (tagName.equals("stockTickFrequencySec"))
						{
							stockTickFrequencySec = Integer.parseInt(xpp.getText().trim());
						}else
						if (tagName.equals("financeWebsite"))
						{
							financeWebsite = xpp.getText().trim();
						}else
						if (tagName.equals("notificationState"))
						{
							String strState = xpp.getText().trim();
							if (strState.equals("true"))
								notificationState = true;
							else 
								notificationState = false;

						}else
						if (tagName.equals("stock"))
						{//add stock
							String symbol = null;
							boolean hasHigh = false;
							boolean hasLow = false;
							float high = 0;
							float low = 0;				
							while(!xpp.getName().equals("stock"))
							{
								tagName = xpp.getName();
								xpp.next();
								if (tagName.equals("name"))
								{
									symbol = xpp.getText().trim();
								}else
								if (tagName.equals("low"))
								{
									low = Float.valueOf(xpp.getText().trim());
								}else
								if (tagName.equals("high"))
								{

									high = Float.valueOf(xpp.getText().trim());
								}else
								if (tagName.equals("haslow"))
								{
									String bool = xpp.getText().trim();
									if (bool.equals("true"))
										hasLow = true;
									else 
										hasLow = false;
									
								}else
								if (tagName.equals("hashigh"))
								{
									String bool = xpp.getText().trim();
									if (bool.equals("true"))
										hasHigh = true;
									else 
										hasHigh = false;
								}
							
								xpp.next();
								if (!xpp.getName().equals("stock"))
									xpp.next();//in stock
							}
							IStockConfiguration stock = new StockConfiguration(symbol, hasHigh, high, hasLow, low);
							map.put(symbol, stock);
							postStockAddedEvent(symbol);
							
						}//stock
						
					}//Start tag

			        eventType = xpp.next();
				}//while
				reader.close();
			}//try
			catch (XmlPullParserException e){

				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			catch (IOException e){
				// TODO Auto-generated catch block
				e.printStackTrace();
			}		

			return map;
		}//getConfigFromXMLFile
		
		
		
		public void addStockToConfigFile(String symbol)
		{
	
			try 
			{		
				FileWriter writer;
				writer = new FileWriter(StockMeTabActivity.activity().getApplication().getFileStreamPath(CONFIG_FILE_NAME),true);
				writer.append("<stock><name>"+symbol+"</name><hashigh>false</hashigh><high>0</high><haslow>false</haslow><low>0</low></stock>\n");
				writer.close();
			} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
			}
			
		}//addStockToConfigFile
		

		public void changeConfigFile(String removeLineWithThisStr, Object value, boolean isString )
		{
		
			try {
				String incomming = null;
				File fSourceStore = StockMeTabActivity.activity().getApplication().getFileStreamPath(CONFIG_FILE_NAME);
				File fDestStore = StockMeTabActivity.activity().getApplication().getFileStreamPath(CONFIG_FILE_NAME+"TEMP");
				fDestStore.delete();
				fDestStore.createNewFile();
				FileReader frStore = new FileReader(fSourceStore);
				FileWriter fwStore = new FileWriter(fDestStore);
				BufferedReader brStore = new BufferedReader(frStore);
				BufferedWriter bwStore = new BufferedWriter(fwStore);
	
				while ((incomming = brStore.readLine()) != null)
				{
	
					if (!incomming.contains(removeLineWithThisStr))
					{
						// Keep information in file
						bwStore.write(incomming);
						bwStore.newLine();
					}
					else
					{//change specific tag
						if (isString)
							bwStore.write("<"+removeLineWithThisStr+">"+(String)value+"</"+removeLineWithThisStr+">");
						else
							bwStore.write("<"+removeLineWithThisStr+">"+(Integer)value+"</"+removeLineWithThisStr+">");
						bwStore.newLine();
					}
				}
				// End of File
				bwStore.close();
				brStore.close();
				frStore.close();
				fwStore.close();
				
		        //Rename 
				fSourceStore.delete();
				fDestStore.renameTo(fSourceStore);
				
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}//changeConfigFile
		
		public void removeStockFromConfigFile(String symbol)
		{
			
			try {
				String incomming = null;
				File fSourceStore = StockMeTabActivity.activity().getApplication().getFileStreamPath(CONFIG_FILE_NAME);
				File fDestStore = StockMeTabActivity.activity().getApplication().getFileStreamPath(CONFIG_FILE_NAME+"TEMP");
				fDestStore.delete();
				fDestStore.createNewFile();
				FileReader frStore = new FileReader(fSourceStore);
				FileWriter fwStore = new FileWriter(fDestStore);
				BufferedReader brStore = new BufferedReader(frStore);
				BufferedWriter bwStore = new BufferedWriter(fwStore);
	
				while ((incomming = brStore.readLine()) != null)
				{
	
					if (!incomming.contains(symbol))
					{
						// Keep information in file
						bwStore.write(incomming);
						bwStore.newLine();
					}
				}
				// End of File
				bwStore.close();
				brStore.close();
				frStore.close();
				fwStore.close();
				
		        //Rename 
				fSourceStore.delete();
				fDestStore.renameTo(fSourceStore);
				
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}//removeStockFromConfigFile
		
		
		public int getNewsHistoryLengthFromConfigFile()
		{
			return this.newsHistoryLength;
		
		}//getNewsHistoryLengthFromConfigFile

		
		public void setNewsHistoryLengthInConfigFile(int length)
		{
			this.newsHistoryLength = length;	
			changeConfigFile("newsHistoryLength",length,false);
	
		
		}//setNewsHistoryLengthInConfigFile
		
		
		public int getNewsTickFrequencyFromConfigFile()
		{
			return this.newsTickFrequencySec;
		
		}//getNewsTickFrequencyFromConfigFile
		
		
		public void setNewsTickFrequencyInConfigFile(int seconds)
		{
			this.newsTickFrequencySec = seconds;
			changeConfigFile("newsTickFrequencySec",seconds,false);
			
		}//setNewsTickFrequencyInConfigFile
		
		
		public int getStockTickFrequencyFromConfigFile()
		{
			return this.stockTickFrequencySec;
			
		}//getStockTickFrequencyFromConfigFile
		
		
		public void setStockTickFrequencyInConfigFile(int seconds)
		{
			this.stockTickFrequencySec = seconds;
			changeConfigFile("stockTickFrequencySec",seconds,false);
			
		}//setStockTickFrequencyInConfigFile
		
		public String getFinanceWebsiteFromConfigFile()
		{
			return this.financeWebsite;
		}//getFinanceWebsiteFromConfigFile
		
		public void setFinanceWebsiteInConfigFile(String siteDatabaseName)
		{
			this.financeWebsite = siteDatabaseName;
			changeConfigFile("financeWebsite",siteDatabaseName, true);
			
						
		}//setFinanceWebsiteInConfigFile

		
		public String[] getDataBaseFinanceWebSites()
		{
			return this.DatabaseWebSites;
		}//setStockLowBoundInConfigFile
		
		
		public String getDefaultFinanceWebsite()
		{
			return this.defaultFinanceWebsite;
		}//getDefaultFinanceWebsite

		
		public int getDefaultNewsHistoryLength()
		{
			return defaultNewsHistoryLength;
		}//getDefaultNewsHistoryLength


		public int getDefaultnewsTickFrequencySec()
		{
			return defaultNewsTickFrequencySec;
		}//getDefaultnewsTickFrequencySec

		
		public int getDefaultStockTickFrequencySec()
		{
			return defaultStockTickFrequencySec;
		}//getDefaultStockTickFrequencySec

		
		
		
		public void updateStockInfoInConfigFile(String symbol , boolean hasHigh,  float high , boolean hasLow , float low)
		{
			try {
				String incomming = null;
				File fSourceStore = StockMeTabActivity.activity().getApplication().getFileStreamPath(CONFIG_FILE_NAME);
				File fDestStore = StockMeTabActivity.activity().getApplication().getFileStreamPath(CONFIG_FILE_NAME+"TEMP");
				fDestStore.delete();
				fDestStore.createNewFile();
				FileReader frStore = new FileReader(fSourceStore);
				FileWriter fwStore = new FileWriter(fDestStore);
				BufferedReader brStore = new BufferedReader(frStore);
				BufferedWriter bwStore = new BufferedWriter(fwStore);
	
				while ((incomming = brStore.readLine()) != null)
				{
	
					if (!incomming.contains(symbol))
					{
						// Keep information in file
						bwStore.write(incomming);
						bwStore.newLine();
					}
					else
					{//save high bound
						String hashigh = (hasHigh ? "true" : "false");
						String haslow = (hasLow ? "true" : "false");
						bwStore.write("<stock><name>"+symbol+"</name><hashigh>"+hashigh+"</hashigh><high>"+high+"</high><haslow>"+haslow+"</haslow><low>"+low+"</low></stock>");
						bwStore.newLine();				

					}//else
				}
				// End of File
				bwStore.close();
				brStore.close();
				frStore.close();
				fwStore.close();
				
		        //Rename 
				fSourceStore.delete();
				fDestStore.renameTo(fSourceStore);
				
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}//setStockLowBoundInConfigFile


		public boolean getNotificationState() {

			return this.notificationState;
		}//getNotificationState


		public void setNotificationState(boolean state) {
			
			this.notificationState = state;
			String strState = (state ? "true" : "false");;

			changeConfigFile("notificationState",strState, true);
			
		}//setNotificationState
		
			
	}//class ConfigFile
	
	
	
	
	public boolean doesStockExists(String symbol)
	{
		return this.stockConfigurationsMap.containsKey(symbol);
	}//doesStockExists
	

	public boolean isHighBoundConfigured(String symbol)
	{
		if (this.stockConfigurationsMap.containsKey(symbol))
		{
			return this.stockConfigurationsMap.get(symbol).isHighBoundConfigured();
		}
				
		return false;
	}//isHighBoundConfigured

	
	public boolean isLowBoundConfigured(String symbol)
	{
		if (this.stockConfigurationsMap.containsKey(symbol))
		{
			return this.stockConfigurationsMap.get(symbol).isLowBoundConfigured();
		}
				
		return false;
	}


	public float getHighBound(String symbol)
	{
		if (this.stockConfigurationsMap.containsKey(symbol))
		{
			return this.stockConfigurationsMap.get(symbol).getHighBound();
		}
				
		return 0;
	}//getHighBound


	
	public float getLowBound(String symbol)
	{
		if (this.stockConfigurationsMap.containsKey(symbol))
		{
			return this.stockConfigurationsMap.get(symbol).getLowBound();
		}
				
		return 0;
	}//getLowBound
					
	
	
	public void setHighBound(String symbol, float high)
	{
		if (this.stockConfigurationsMap.containsKey(symbol))
		{
			
			IStockConfiguration stock = this.stockConfigurationsMap.get(symbol);
			stock.setHighBound(high);
			this.configFile.updateStockInfoInConfigFile(symbol,stock.isHighBoundConfigured(),stock.getHighBound(),stock.isLowBoundConfigured(), stock.getLowBound());

		}
	}
						


	public void setLowBound(String symbol, float low)
	{
		if (this.stockConfigurationsMap.containsKey(symbol))
		{
			
			IStockConfiguration stock = this.stockConfigurationsMap.get(symbol);
			stock.setLowBound(low);
			this.configFile.updateStockInfoInConfigFile(symbol,stock.isHighBoundConfigured(),stock.getHighBound(),stock.isLowBoundConfigured(), stock.getLowBound());

		}
	}
						
					
	
	public void addStock(String symbol) 
	{
		
		if (!this.stockConfigurationsMap.containsKey(symbol))
		{
			IStockConfiguration stock = new StockConfiguration(symbol);
			this.stockConfigurationsMap.put(symbol, stock);
			this.configFile.addStockToConfigFile(symbol);
			
			// This method should be called last in order to notify listeners after all changes take effect
			this.postStockAddedEvent(symbol);
		}
	}

	public void removeStock(String symbol) 
	{

		this.stockConfigurationsMap.remove(symbol);
		this.configFile.removeStockFromConfigFile(symbol);

		// This method should be called last in order to notify listeners after all changes take effect
		this.postStockRemovedEvent(symbol);
	}

	public int getNewsHistoryLength() {
		
		return this.configFile.getNewsHistoryLengthFromConfigFile();
	}

	public void setNewsHistoryLength(int length) {
		
		this.configFile.setNewsHistoryLengthInConfigFile(length);
		// This method should be called last in order to notify listeners after all changes take effect
		this.postHistoryLengthChangedEvent();
	}

	public int getNewsTickFrequency() {

		return this.configFile.getNewsTickFrequencyFromConfigFile();
	}

	public void setNewsTickFrequency(int seconds) {

		this.configFile.setNewsTickFrequencyInConfigFile(seconds);
		// This method should be called last in order to notify listeners after all changes take effect
		this.postNewsTickFrequencyChangedEvent();
	}

	public int getStockTickFrequency() {

		return this.configFile.getStockTickFrequencyFromConfigFile();
	}

	public void setStockTickFrequency(int seconds) {
		
		this.configFile.setStockTickFrequencyInConfigFile(seconds);
		// This method should be called last in order to notify listeners after all changes take effect
		this.postStockTickFrequencyChangedEvent();
	}

	public String getFinanceWebsite() {
		
		return this.configFile.getFinanceWebsiteFromConfigFile();
	}

	public void setFinanceWebsite(String siteDatabaseName) {

		this.configFile.setFinanceWebsiteInConfigFile(siteDatabaseName);
		// This method should be called last in order to notify listeners after all changes take effect
		this.postFinanceWebsiteChangedEvent();
	}
	
	public String[] getDataBaseFinanceWebSites()
	{
		return this.configFile.getDataBaseFinanceWebSites();
	}//getDataBaseFinanceWebSites
	
	
	
	public void restoreDefault()
	{
		
		this.setFinanceWebsite(this.configFile.getDefaultFinanceWebsite());
		this.setNewsHistoryLength(this.configFile.getDefaultNewsHistoryLength());
		this.setNewsTickFrequency(this.configFile.getDefaultnewsTickFrequencySec());
		this.setStockTickFrequency(this.configFile.getDefaultStockTickFrequencySec());
		
	}//restoreDefault
	
	
	
	public void registerStockAddedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.STOCK_ADDED_EVENT).add(listener);
	}

	public void unregisterStockAddedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.STOCK_ADDED_EVENT).remove(listener);
	}

	public void registerStockRemovedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.STOCK_REMOVED_EVENT).add(listener);
	}

	public void unregisterStockRemovedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.STOCK_REMOVED_EVENT).remove(listener);
	}

	public void registerHistoryLengthChangedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.HISTORY_LENGTH_CHANGED_EVENT).add(listener);		
	}

	public void unregisterHistoryLengthChangedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.HISTORY_LENGTH_CHANGED_EVENT).remove(listener);		
	}

	public void registerNewsTickFrequencyChangedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.NEWS_TICK_FREQUENCY_CHANGED_EVENT).add(listener);				
	}

	public void unregisterNewsTickFrequencyChangedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.NEWS_TICK_FREQUENCY_CHANGED_EVENT).remove(listener);				
	}

	public void registerStockTickFrequencyChangedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.STOCK_TICK_FREQUENCY_CHANGED_EVENT).add(listener);						
	}

	public void unregisterStockTickFrequencyChangedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.STOCK_TICK_FREQUENCY_CHANGED_EVENT).remove(listener);
	}
	
	public void registerFinanceWebsiteChangedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.FINANCE_WEBSITE_CHANGED_EVENT).add(listener);
	}

	public void unregisterFinanceWebsiteChangedListener(IConfigurationChangedListener listener) {
		if (listener != null)
			this.event2listeners.get(EConfigurationChangedEvents.FINANCE_WEBSITE_CHANGED_EVENT).remove(listener);		
	}

	/**
	 */
	protected void postStockAddedEvent(String symbol) {
		this.postConfigurationChangedEvent(EConfigurationChangedEvents.STOCK_ADDED_EVENT, symbol);
	}

	
	/**
	 */
	protected void postStockRemovedEvent(String symbol) {
		this.postConfigurationChangedEvent(EConfigurationChangedEvents.STOCK_REMOVED_EVENT, symbol);
	}


	/**
	 */
	protected void postHistoryLengthChangedEvent() {
		this.postConfigurationChangedEvent(EConfigurationChangedEvents.HISTORY_LENGTH_CHANGED_EVENT, this.getNewsHistoryLength());
	}


	/**
	 */
	protected void postStockTickFrequencyChangedEvent() {
		this.postConfigurationChangedEvent(EConfigurationChangedEvents.STOCK_TICK_FREQUENCY_CHANGED_EVENT, this.getStockTickFrequency());
	}


	/**
	 */
	protected void postNewsTickFrequencyChangedEvent() {
		this.postConfigurationChangedEvent(EConfigurationChangedEvents.NEWS_TICK_FREQUENCY_CHANGED_EVENT, this.getNewsTickFrequency());
	}
	
	/**
	 */
	protected void postFinanceWebsiteChangedEvent() {
		this.postConfigurationChangedEvent(EConfigurationChangedEvents.FINANCE_WEBSITE_CHANGED_EVENT, this.getFinanceWebsite());
	}


	private void initListenersMap() {
		this.event2listeners = new HashMap<EConfigurationChangedEvents, Collection<IConfigurationChangedListener>>();
		for (EConfigurationChangedEvents event : EConfigurationChangedEvents.values())
			this.event2listeners.put(event, new HashSet<IConfigurationChangedListener>());
	}
	
	private void postConfigurationChangedEvent(EConfigurationChangedEvents event, Object arg) {
		for (IConfigurationChangedListener listener : this.event2listeners.get(event))
			listener.notifyConfigurationChanged(arg);
	}


	public void setHighEnableDisable(String symbol, boolean bool) {
		
		if (this.stockConfigurationsMap.containsKey(symbol))
		{
			IStockConfiguration stock = this.stockConfigurationsMap.get(symbol);
			stock.setHighEnableDisable(bool);
			this.configFile.updateStockInfoInConfigFile(symbol,stock.isHighBoundConfigured(),stock.getHighBound(),stock.isLowBoundConfigured(), stock.getLowBound());
			
		}
		
	}


	public void setLowEnableDisable(String symbol, boolean bool) {
		
		if (this.stockConfigurationsMap.containsKey(symbol))
		{
			IStockConfiguration stock = this.stockConfigurationsMap.get(symbol);
			stock.setLowEnableDisable(bool);
			this.configFile.updateStockInfoInConfigFile(symbol,stock.isHighBoundConfigured(),stock.getHighBound(),stock.isLowBoundConfigured(), stock.getLowBound());
		}
		
	}
	
	public Collection<String> getStockSymbols() {
		return this.stockConfigurationsMap.keySet();
	}


	public boolean getNotificationState() {

		return this.configFile.getNotificationState();
	}


	public void setNotificationState(boolean state) {

		this.configFile.setNotificationState(state);
		
	}
}
